<template>


    <div style="height:100%">
        <div style="padding:30px;">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-button type="primary">
                        <router-link to="videoadd" tag="span">视频添加</router-link>
                    </el-button>
                </el-col>
                <el-col :span="6">
                    <el-input v-model="p" placeholder="请输入内容"></el-input>
                </el-col>
                <el-col :span="6">
                    <el-button type="primary" @click="submit">搜索</el-button>
                </el-col>

            </el-row>


            <br>
            <br>

            <el-table
                    :data="tableData"
                    border
                    style="width: 100%">
                <el-table-column
                        fixed
                        prop="id"
                        label="id"
                        width="60">
                </el-table-column>
                <el-table-column

                        prop="name"
                        label="名称"
                >
                </el-table-column>
                <el-table-column
                        prop="level1.name"
                        label="分类1"
                >
                </el-table-column>
                <el-table-column
                        prop="level2.name"
                        label="分类2"
                >
                </el-table-column>
                <el-table-column

                        label="封面图"
                >
                    <template slot-scope="scope">
                        <img width="50" :src="scope.row.image.url" alt="">
                    </template>
                </el-table-column>

                <el-table-column
                        fixed="right"
                        label="操作"
                        width="100">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
                        <router-link :to="{name:'videosave',params:{id:scope.row.id}}">修改</router-link>
                    </template>
                </el-table-column>
            </el-table>

            <br>
            <el-pagination
                    background
                    :page-size="10"
                    layout="prev, pager, next"
                    :current-page="currentPage"
                    @current-change="handleCurrentChange"
                    :total="total">
            </el-pagination>
        </div>
    </div>

</template>

<script>

    export default {
        mounted() {
            let page = {
                page: this.currentPage
            }
            axios.post('/api/GetVideoList', page).then(rew => {

                this.tableData = rew.data.data

                this.total = rew.data.zpage
            })

        },
        methods: {
            handleClick(row) {
                this.$confirm('是否删除该题目?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {


                    axios.post('/api/VideoDels', row).then(rew => {
                        var index = this.tableData.indexOf(row)
                        this.tableData.splice(index, 1);
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            handleCurrentChange(currentPage) {
                let page = {
                    page: currentPage
                }
                axios.post('/api/GetSubTwoVideo', page).then(rew => {

                    this.tableData = rew.data.data

                    this.total = rew.data.zpage
                })
            },
            hand(val, id) {
                let data = {
                    is_zy: val,
                    id: id
                }
                axios.post('/zy', data).then(rew => {

                })
            },
            ycthand(val, id) {
                let data = {
                    is_yct: val,
                    id: id
                }
                axios.post('/yc', data).then(rew => {

                })
            },
            submit(){
                axios.post('/api/SearchVideoByp',{p:this.p}).then(rew=>{
                    this.tableData = rew.data.data

                })
            }
        },
        data() {
            return {
                tableData: [],
                currentPage: 1,
                total: 0,
                p: ''
            }
        }
    }
</script>
<style scoped>

</style>